Skip to content

Rectify: Dispatch Envelope Shape Discrimination Immunity#4118

Merged
Trecek merged 3 commits into
developfrom
pretty-output-hook-strips-critical-fields-from-failed-dispat/4111
Jun 26, 2026
Merged

Rectify: Dispatch Envelope Shape Discrimination Immunity#4118
Trecek merged 3 commits into
developfrom
pretty-output-hook-strips-critical-fields-from-failed-dispat/4111

Conversation

@Trecek

@Trecek Trecek commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

The _fmt_dispatch_food_truck formatter conflates two structurally distinct success=False response shapes — DispatchRejected (subprocess never started) and DispatchCompleted(success=False) (subprocess ran and failed) — under a single early-return branch. This strips critical fields (dispatched_session_id, dispatch_status, reason, token_usage, elapsed_seconds) from failed dispatches that actually ran, causing the orchestrator to believe no session ever existed. The architectural solution introduces a typed kind discriminator field at the envelope layer, adds the field to the existing DispatchEnvelopeResult TypedDict, and adds per-shape formatter contract tests that structurally prevent any formatter from silently dropping fields for a given envelope shape.

Implementation Plan

Plan file: /home/talon/projects/autoskillit-runs/remediation-20260626-152751-009727/.autoskillit/temp/rectify/rectify_dispatch_envelope_shape_discrimination_2026-06-26_153500.md

🤖 Generated with Claude Code via AutoSkillit

Closes #4111

Token Usage Summary

Step Model count uncached output cache_read peak_ctx turns cache_write time
rectify* opus[1m] 1 4.9k 16.0k 1.3M 109.9k 52 90.8k 13m 50s
review_approach* sonnet 1 60 8.3k 257.1k 51.2k 17 37.9k 6m 15s
dry_walkthrough* opus 1 46 9.5k 1.3M 86.7k 52 87.5k 9m 8s
implement* MiniMax-M3 1 108.6k 21.8k 3.0M 0 93 0 5m 48s
assess* opus[1m] 1 48 4.6k 1.0M 58.7k 43 39.6k 5m 9s
audit_impl* sonnet 1 539 11.2k 284.0k 47.9k 20 41.0k 6m 21s
prepare_pr* MiniMax-M3 1 43.4k 2.3k 152.5k 0 14 0 30s
compose_pr* MiniMax-M3 1 36.8k 1.4k 171.8k 0 11 0 31s
review_pr* sonnet 3 510 112.4k 4.0M 99.9k 152 225.2k 28m 58s
ci_conflict_fix* opus[1m] 1 26 2.1k 306.4k 45.6k 19 26.6k 1m 14s
diagnose_ci* MiniMax-M3 1 54.4k 2.3k 297.6k 0 20 0 53s
resolve_ci* opus[1m] 1 54 6.1k 1.7M 77.7k 49 58.5k 4m 29s
Total 249.4k 198.0k 13.8M 109.9k 607.0k 1h 23m

* Step used a non-Anthropic provider; caching behavior may differ.

Token Efficiency

Step LoC Changed cache_read/LoC cache_write/LoC output/LoC
rectify 0
review_approach 0
dry_walkthrough 0
implement 288 10507.4 0.0 75.7
assess 3 344689.7 13199.0 1535.7
audit_impl 0
prepare_pr 0
compose_pr 0
review_pr 0
ci_conflict_fix 381 804.2 69.8 5.5
diagnose_ci 0
resolve_ci 1 1706644.0 58532.0 6130.0
Total 673 20433.8 902.0 294.2

Model Usage Breakdown

Model steps uncached output cache_read cache_write time
opus[1m] 4 5.0k 28.8k 4.3M 215.5k 24m 43s
sonnet 3 1.1k 131.8k 4.5M 304.0k 41m 36s
opus 1 46 9.5k 1.3M 87.5k 9m 8s
MiniMax-M3 4 243.2k 27.8k 3.6M 0 7m 42s

Trecek and others added 3 commits June 26, 2026 15:57
…igations

The _fmt_dispatch_food_truck formatter conflated two structurally distinct
success=False response shapes (DispatchCompleted(success=False) and
DispatchRejected) under a single early-return branch, stripping critical
fields (dispatched_session_id, dispatch_status, reason, token_usage,
elapsed_seconds) from failed dispatches that actually ran.

Changes:
- Add 'kind' discriminator to DispatchCompleted.to_envelope() and
  DispatchRejected.to_envelope() in fleet/state_types.py
- Add 'kind' to DispatchEnvelopeResult TypedDict in server/tools/_types.py
- Replace formatter's success-based discrimination with kind-based
  discrimination, with a fallback for fleet_error() envelopes
- Add per-shape required-field frozensets
  (_FMT_DISPATCH_COMPLETED_REQUIRED, _FMT_DISPATCH_REJECTED_REQUIRED)
- Add 'kind' to _FMT_DISPATCH_FOOD_TRUCK_SUPPRESSED frozenset
- Update _dispatch_food_truck_json_producer to exercise
  DispatchCompleted(success=False)
- Add six new tests covering shape discrimination, envelope contract,
  structural exclusion guard, per-shape obligations, json producer
  coverage, and fleet_error() fallback path

Issue #4111
Replace fragile if/elif chains in test_shape_field_obligations_per_kind
that silently skip unrecognized fields with data-driven maps that fail
explicitly when a new field is added to the required frozenset. Also
removes the redundant `key = field` intermediate variable.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The merged-dict assertion let kind pass even if the completed_failure
shape specifically dropped it.  Now parse completed_failure.to_envelope()
independently and verify kind is present in that single envelope.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Trecek Trecek added this pull request to the merge queue Jun 26, 2026
Merged via the queue into develop with commit e315dbb Jun 26, 2026
3 checks passed
@Trecek Trecek deleted the pretty-output-hook-strips-critical-fields-from-failed-dispat/4111 branch June 26, 2026 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant